package com.cobra.rdd.operator.transform

import org.apache.spark.{SparkConf, SparkContext}

//将每个分区形成一个数组
object Spark09_RDD_Operator_Transform_glom_test {
  def main(args: Array[String]): Unit = {
    val sparkConf = new SparkConf().setMaster("local[*]").setAppName("mapPartitionsWithIndex")
    val sc = new SparkContext(sparkConf)
    val rdd = sc.makeRDD(List(1, 2, 3, 4),2)
    val glomRDD = rdd.glom()
    val maxRDD = glomRDD.map(
      array => {
        array.max
      }
    )
    val sum = maxRDD.collect().sum
    println(sum)
    sc.stop()
  }
}
